---
title: "Connecting to a GCP Cloud SQL database"
sidebarTitle: "GCP Cloud SQL"
description: "Stream changes from GCP Cloud SQL to other Google services and beyond. Learn how to enable logical replication and connect Sequin to your database."
icon: "google"
iconType: "solid"
---

import CreateSequinDbUser from '/snippets/create-sequin-db-user.mdx';

This guide provides step-by-step instructions to connect your [GCP Cloud SQL](https://cloud.google.com/sql) database to Sequin.

## Provision a Postgres user for Sequin
<CreateSequinDbUser />

## Enable logical replication on GCP Cloud SQL

By default, logical replication is not enabled on GCP Cloud SQL. You can double check if logical replication is enabled by connecting to your database and running the following commands:

```sql
SHOW cloudsql.logical_decoding;
SHOW cloudsql.logical_replication;
```

If the output to either of these commands is `off`, then logical decoding or replication is not enabled.

To enable it, follow these steps:

<Warning>Enabling replication requires a restart of your database instance.</Warning>

<Steps titleSize="h3">
  <Step title="Enable pglogical flag">
    In the Google Cloud Console, navigate to your Cloud SQL instance and follow these steps:

    1. Go to the "Configuration" tab for your database instance
    2. Click "Edit configuration"
    3. Under "Flags" section, add a new flag: `cloudsql.enable_pglogical=on`
    4. Click "Save" to apply the changes
  </Step>
  <Step title="Restart your database instance">
    After setting the flag, you need to restart your Cloud SQL instance for the changes to take effect. In the Google Cloud Console:

    1. Go to the "Overview" tab of your Cloud SQL instance
    2. Click the "Restart" button at the top of the page
    3. Confirm the restart when prompted
  </Step>
</Steps>

## Connect Sequin to your GCP Cloud SQL database

After enabling logical replication on GCP Cloud SQL, you'll now connect to your database in Sequin.

<Steps titleSize="h3">
  <Step title="Enter connection details in Sequin">
    In the Sequin Console, click on the **Connect Database** button and enter the credentials for your GCP Cloud SQL database:

    <Note>
      You can find these connection details in your GCP Cloud SQL instance overview.
    </Note>

    - Host: Your Cloud SQL instance IP address
    - Port: 5432 (default Postgres port)
    - Database: Your database name
    - Username: The sequin database user you created earlier
    - Password: The password for your sequin database user

    Make sure to enable the "SSL" option for secure connection.
  </Step>
  <Step title="Create a publication">
    Connect to your database using the SQL client of your choice and execute the following SQL query to create a publication:

    ```sql
    CREATE PUBLICATION sequin_pub FOR TABLE table1, table2, table3 WITH (publish_via_partition_root = true);
    ```

    If you want to publish changes from all tables, you can use:

    ```sql
    CREATE PUBLICATION sequin_pub FOR ALL TABLES WITH (publish_via_partition_root = true);
    ```
  </Step>
  <Step title="Create a replication slot">
    Next, create a replication slot to capture changes from the publication:

    ```sql
    SELECT pg_create_logical_replication_slot('sequin_slot', 'pgoutput');
    ```
  </Step>

  <Step title="Enter the replication slot details in Sequin">
    Back in the Sequin Console, enter the name of the replication slot (e.g. `sequin_slot`) and publication (e.g. `sequin_pub`) you just created. Then, name your database and click "Create Database".
  </Step>
</Steps>

## Create a sink

With your GCP Cloud SQL database connected to Sequin, you are ready to create a sink. Follow one of our guides below to get started:

<CardGroup cols={2}>
   <Card
      title="Stream to GCP Pub/Sub"
      icon="aws"
      href="/how-to/stream-postgres-to-gcp-pubsub"
   >
      Send changes to GCP Pub/Sub topics to trigger Cloud Functions and power event-driven architectures
   </Card>
  <Card
    title="Stream to Webhooks"
    icon="webhook"
    href="/how-to/stream-postgres-to-a-webhook-endpoint"
  >
    Send database changes to your HTTP endpoints to trigger workflows and keep services in sync
  </Card>
  <Card
    title="Stream to Redis"
    icon="layer-group"
    href="/how-to/stream-postgres-to-redis-stream"
  >
    Stream changes to Redis Streams for real-time data processing and caching
  </Card>
  <Card
    title="Stream to Kafka"
    icon="code-branch"
    href="/how-to/stream-postgres-to-kafka"
  >
    Publish database changes to Kafka topics for event streaming and processing
  </Card>
</CardGroup>



